package 反射第二遍.demo19;

import java.lang.reflect.Field;

/**
 * @author wql
 * @version 1.0
 * @date 2022/10/27 15:49
 */

public class Test {
    public static void main(String[] args) throws Exception{
        Class<haha> hahaClass = haha.class;
        haha haha = hahaClass.newInstance();

        Field address = hahaClass.getDeclaredField("address");
        address.set(haha, "郑州");
        System.out.println(haha);

        Field num = hahaClass.getDeclaredField("num");
        num.setAccessible(true);
        num.set(haha,12);
        Object o = num.get(haha);
        System.out.println("o = " + o);
    }
}
class hehe{
    public String name;
    private  Integer age;
}
class haha extends hehe{
    public String address;
    private Integer num;

    @Override
    public String toString() {
        return "haha{" +
                "address='" + address + '\'' +
                ", num=" + num +
                '}';
    }
}
